package com.mb.app.controller;

import com.mb.app.domain.TbMemberFeedback;
import com.mb.app.service.ITbMemberFeedbackService;
import com.mb.common.config.CommonConfig;
import com.mb.common.utils.DateUtils;
import com.mb.common.utils.PageUtils;
import com.mb.common.utils.Query;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 反馈意见  前端控制器
 * </p>
 *
 * @author liliping
 * @since 2019-05-21
 */
@Slf4j
@Controller
@RequestMapping("/app/memberfeedback")
public class TbMemberFeedbackController {
    @Autowired
    private ITbMemberFeedbackService memberFeedbackService;
    @Autowired
    private CommonConfig commonConfig;

    @GetMapping("/index")
    String index(Model model){
        // 查询反馈信息
        Map<String,Object> map = new HashMap<String,Object>();
        List<TbMemberFeedback> memberFeedbacks = memberFeedbackService.queryList(map);
        model.addAttribute("memberFeedbacks",memberFeedbacks);
        return "/app/memberFeedback/feedBackList";
    }

    @ResponseBody
    @GetMapping("/list")
    public PageUtils list(@RequestParam Map<String, Object> params) {
        // 查询列表数ju
        String createTime = (String) params.get("createTime");
        if (StringUtils.isNotEmpty(createTime)) {
            params.put("startTime", DateUtils.parse(createTime.substring(0,10),DateUtils.DATE_PATTERN));
            params.put("endTime",createTime.substring(13,23)+" 23:59:59");
        }
        Query query = new Query(params);
        List<TbMemberFeedback> list = memberFeedbackService.queryList(query);
        int total = memberFeedbackService.count(query);
        PageUtils pageUtils = new PageUtils(list,total);
        return pageUtils;
    }

    @GetMapping("/dtl/{id}")
    String dtl(@PathVariable("id") Long id, Model model){
        model.addAttribute("memberFeedback",memberFeedbackService.selectFeedback(id));
        return "/app/memberFeedback/feedbackInfo";
    }

}
